package com.shujia.controller;

import com.shujia.entity.Emp;
import com.shujia.service.EmpService;
import com.shujia.service.impl.EmpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("emp")

public class EmpController {
    @Autowired
    private EmpServiceImpl empService;
    @RequestMapping("add")
    public String save1(){
        return "add";
    }
    @PostMapping("add2")
    public String save2(Emp emp, Model model){
        empService.save(emp);
        List<Emp> emps = empService.findAll();
        model.addAttribute("emps",emps);
        return "index";
    }


}
